<?php
namespace Wap\Controller;
use Org\Yike\FangCms;
class IndexController extends CommonController {
    public function _initialize(){
        parent::_initialize();
        $this->title= '首页';
    }

    public function index(){
        $map = 'status=1';
        $houses = M ('used')->where ($map)->limit (0,10)->select ();
        foreach ($houses as &$h){
            $imgs = json_decode($h['file']);
            $h['file'] = $imgs[0]->img;
            switch ($h['aspect']){
                case 1:
                    $h['aspect'] ='东 ';
                    break;
                case 2:
                    $h['aspect'] ='西';
                    break;
                case 3:
                    $h['aspect'] ='南';
                    break;
                case 4:
                    $h['aspect'] ='北 ';
                    break;
                case 5:
                    $h['aspect'] ='东西';
                    break;
                case 6:
                    $h['aspect'] ='南北';
                    break;
                case 7:
                    $h['aspect'] ='东南';
                    break;
                case 8:
                    $h['aspect'] ='东北';
                    break;
                case 9:
                    $h['aspect'] ='西南' ;
                    break;
                case 10:
                    $h['aspect'] ='西北';
                    break;
            }

        }
        $this->assign ('page', 1);
        $this->assign ('useds', $houses);
        $this->display();
    }
    public function loading (){
        $ori_page = I ('post.page', '');
        $page = $ori_page*10;
        $map = 'status=1';
        $houses = M ('used')->where ($map)->limit ($page,10)->select ();

        if ($houses){
            foreach ($houses as &$h){
                $imgs = json_decode($h['file']);
                $h['file'] = $imgs[0]->img;
                switch ($h['aspect']){
                    case 1:
                        $h['aspect'] ='东 ';
                        break;
                    case 2:
                        $h['aspect'] ='西';
                        break;
                    case 3:
                        $h['aspect'] ='南';
                        break;
                    case 4:
                        $h['aspect'] ='北 ';
                        break;
                    case 5:
                        $h['aspect'] ='东西';
                        break;
                    case 6:
                        $h['aspect'] ='南北';
                        break;
                    case 7:
                        $h['aspect'] ='东南';
                        break;
                    case 8:
                        $h['aspect'] ='东北';
                        break;
                    case 9:
                        $h['aspect'] ='西南' ;
                        break;
                    case 10:
                        $h['aspect'] ='西北';
                        break;
                }

            }
            exit (json_encode(array ('state'=>'ok','data'=>$houses,'page'=>$ori_page+1)));
        }
        exit (json_encode(array ('state'=>'0','data'=>'','page'=>$ori_page+1)));
    }

}